<?php header("Content-Type:text/html;   charset=utf-8"); ?>
<script type="text/javascript">
    $(function(){
        $("#textAdvertiseName").bind("blur",checkAdvertiseName);

        loadAdvertiseName();
        $("#btnSubmitNewAdvertise").bind("click",submitAdvertise);
    });
    function submitAdvertise(){
        if(checkAdvertiseName()==false)
            return;

        var id = $("#hdidAdvertise").val();
        var advertiseName = $("#textAdvertiseName").val();
        var advertiseStart = $("#textAdvertiseStart").val();
        var advertiseEnd = $("#textAdvertiseEnd").val();
        var params = {
            id:id,
            title:advertiseName,
            start_time:advertiseStart,
            end_time:advertiseEnd
        };

        $.ajax({
            type:"post",
            url:"admin.php/advertise/addAdvertise",
            dataType:"json",
            data:params,
            success:function(data){
                parent.loadAdvertise();
                alert("提交成功");
                $("#btnCloseAdvertiseName").trigger("click");
            }
        });
    }

    function loadAdvertiseName(){
        var id = $("#hdidAdvertise").val();
        if(id==0)
            return;

        var params = {id:id};
        $.ajax({
            type:"post",
            url:"admin.php/advertise/loadNewAdvertise",
            dataType:"json",
            data:params,
            success:function(data){
                $("#textAdvertiseName").val(data.title);
                $("#textAdvertiseStart").val(data.start_time);
                $("#textAdvertiseEnd").val(data.end_time);

            }
        });
    }
    function checkAdvertiseName(){

        var columnname = $("#textAdvertiseName").val();
        if(IsEmpty(columnname)){
            SetError("textAdvertiseName","广告名称不能为空");
            return false;
        }
        var len = columnname.length;
        if(len>100){
            SetError("textAdvertiseName","最多100字符");
            return false;
        }
        SetOK("textAdvertiseName");
        return true;
    }

</script>
<div class="pageContent">
    <form class="pageForm required-validate">
        <div class="pageFormContent" style="width: 98%;" layoutH="56">
            <table class="tableNewUser">
                <tr>
                    <td>广告名称：</td>
                    <td><input id="textAdvertiseName" type="text" value="" /></td>
                </tr>
                <tr>
                    <td>开始时间：</td>
                    <td><input type="text" readonly="true" class="date textInput readonly valid" id="textAdvertiseStart"></td>
                </tr>
                <tr>
                    <td>结束时间：</td>
                    <td><input type="text" readonly="true" class="date textInput readonly valid" id="textAdvertiseEnd"></td>
                </tr>
                <tr>
                    <td colspan="2" style='line-height: 40px'>&nbsp;&nbsp;</td>
                </tr>
            </table>
            <input type="hidden" id="hdidAdvertise"
                   value="<?php if(isset($_GET["id"])) print $_GET["id"]; else print 0;?>">

            <div class="buttonActive" style="width: 120px; margin-left: 50px;">
                <div class="buttonContent">
                    <button id="btnSubmitNewAdvertise" type="button" style="width: 80px">提
                        交</button>
                </div>
            </div>

            <div class="button" style="text-align: right">
                <div class="buttonContent" style="text-align: right">
                    <button id="btnCloseAdvertiseName" type="button" class="close"
                            style="width: 80px">取 消</button>
                </div>
            </div>
        </div>
    </form>
</div>
